<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function getAcccountId($account_name) {
    $result_uin = Transform_Account2ID($account_name, $error);
    return $result_uin?$result_uin:'-1';
}

function get_user_info_from_net($users, $fields)
{
	if (empty($users) || !is_array($users))
	{
		return false;
	}

	return BDBMemberCenterEngine_GetMultiRows($users, $fields);
}
function charset($charset='utf-8')
{
    echo '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'">';
}
function js_local_go($url,$msg='',$target='self')
{
	$js_code = "<script language='javascript'>";
	if($msg) $js_code.="alert('$msg');";
	$js_code.="{$target}.location='{$url}';</script>";
	echo $js_code;
}
//51显示帐号,by yaq
function show_51_account($account)
{
	if (is_numeric($account)) 
	{
		$ret = Transform_Uin2Entire($account, &$errorCode);
		if ($ret['extra_account']) {
			$xs_account = $ret['extra_account'];
		}
		else
			$xs_account = $ret['good_id'];
	} 
	else 
	{
		$xs_account = $account;
	}
	return $xs_account;
}

function is_log_51account()
{
	if (empty($_SESSION['Account'])) {
		load_library('pub:core/FOPassPort', false);//验证登录
    	if (!empty($_SESSION) && strtolower(mb_detect_encoding($_SESSION['AccountID'])) != 'utf-8')
		{
			foreach ($_SESSION as $key=>$value)
			{
				$_SESSION[$key] = iconv('gbk', 'utf-8', $value);	
			}
		}
	}
}

####取用户的vip等级
function get_user_vip_level($vip, $vipscore)
{
	if (!is_numeric($vip) || !is_numeric($vipscore))
	{
		return false;
	}
	#require_once(LIB51_ROOT . 'photo/face.helper.php');
	return get_vip_ico('link', $vip, $vipscore, false);
}
###取用户的51等级
function get_user_51_level($user)
{
	$url = "";
	if (empty($user))
	{
		return false;
	}
	#require_once(LIB51_ROOT . 'user/ScorePassPort.php');
	$res = FOScore_RetrieveIntegral($user);
	if (!empty($res))
	{
		$url = FOScore_getScoreLevel($res, 'levelPic');
	}
	return $url;
}

function X5_Transform_Account($param) {
	if (is_numeric($param)) {
		$row = Transform_Goodid2Others($param, $error = null);
	} else {
		$row = Transform_Extraaccount2Others($param, $error = null);
	}
    if (isset($row['account']) && $row['account'] != '') {
    	return $row['account'];
    }
    
    return false;
}

    function get_dmz_uiserver_userinfo($accountID,$zoneID=1)
    {
    	if (empty($accountID) || !is_numeric($accountID))
        {
            return false;
        }
        
    	$key = 'dmz_user_'.$zoneID.'_'.$accountID;
		$ret = Mcache::read(MCACHE_DMZ_USER_INFO, $key);
		if ($ret)
		{
			return $ret;
		}
		else
		{
			load_extend('uiserver');
			$client = new DMZ_UIClient();
			$ret = $client->get_role_info($zoneID, $accountID);
			if ($ret) {
				if (MC_USED && $ret['roleid'])
				{
					$key = 'dmz_user_'.$zoneID.'_'.$ret['roleid'];
					Mcache::write(MCACHE_DMZ_USER_INFO, $key, $ret,3600);//缓存用户游戏信息1小时
				}
			}
			else 
			{
				$ret = false;
			}
			//$client->close();
			return $ret;
		}	
    }

if(!function_exists('get_client_ip'))
{
	function get_client_ip()
	{
		if(getenv('HTTP_X_FORWARDED_FOR') != '')
		{
			$client_ip = (!empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( (!empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR);
			$entries = explode(',', getenv('HTTP_X_FORWARDED_FOR'));
			reset($entries);
			while (list(, $entry) = each($entries))
			{
				$entry = trim($entry);
				if (preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry, $ip_list) )
				{
					$private_ip = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', '/^10\..*/', '/^224\..*/', '/^240\..*/');
					$found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
					if ($client_ip != $found_ip)
					{
						$client_ip = $found_ip;
						break;
					}
				}
			}
		}
		else
		{
			$client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
		}
		// 真实的IP在以逗号分隔的最后一个, 当然如果没用代理, 没伪造IP, 就没有逗号分离的IP
		if ($p = strrpos($client_ip, ",")) {
			$client_ip = substr($ip, $p+1);
		}
		return $client_ip;
	}
}

?>
